home *** CD-ROM | disk | FTP | other *** search
/ BBS Toolkit / BBS Toolkit.iso / rbbs_pc / r2dbf121.zip / MBF2NUM.C < prev   
Text File  |  1991-02-22  |  1KB  |  50 lines

  1. /*
  2.   Microsoft Binary Format to Number: Emulates BASIC's CVS()
  3.   Eric J. Givler
  4.   2/20/91
  5. */
  6.  
  7. #include "i:\clipper\nandef.h"
  8. #include "i:\clipper\extend.h"
  9. #include "i:\tc\include\stdio.h"
  10.  
  11.  
  12. CLIPPER Cvs()                /* void main(void) */
  13. {
  14.    unsigned char s[4];       /*  = "0000"; */
  15.    unsigned long l;          /* result     */
  16.    unsigned char e;          /* exponent   */
  17.    char *str1;
  18.    char sh,i;
  19.  
  20.    str1 = _parc(1);           /* strcpy( s, _parc(1)); */
  21.  
  22.    s[0] = *str1;
  23.    s[1] = *(str1+1);
  24.    s[2] = *(str1+2);
  25.    s[3] = *(str1+3);
  26.  
  27.    l = 0;
  28.    if (s[3] == 0)
  29.    {
  30.       _retnl(l);
  31.    }
  32.    else
  33.    {
  34.       i = 0;
  35.       e    = s[3] & 127;        /* exponent byte 127 normalized */
  36.       s[2] = s[2] | 128;        /* turn on 1st bit of byte 3!   */
  37.       for(i=0; i < 3; i++)      /* while (i < 3) */
  38.       {
  39.      sh = e - 8 * (i+1);
  40.      if (sh < 0)
  41.      {
  42.           sh = -sh;
  43.           l += (long)s[2-i] >> sh;
  44.      }
  45.      else l += (long)s[2-i] << sh;
  46.       }
  47.    _retnl(l);
  48.    }
  49. }
  50.